package com.example.communicationfragment.activity;

import androidx.appcompat.app.AppCompatActivity;

public class Main_viewmodel_Activity extends AppCompatActivity {
/*
    static int count = 0;
    private ItemViewModel itemViewModel;  // 1. 声明 ViewModel 变量

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button sendButton = findViewById(R.id.send_button);
        sendButton.setOnClickListener(v -> {
            // 3. 设置数据（这个数据会传递给 Fragment)
            itemViewModel.setData("Hello from Activity 被点击了 " + ++count + "次");
        });

        // 2. 通过 ViewModelProvider 获取 ViewModel
        itemViewModel = new ViewModelProvider(this).get(ItemViewModel.class);

        // 4. 添加 Fragment 到 Activity 中
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new BlankFragment()).commit();
    }*/
}